package cn.tangsihai.hrm.web.controller;

import cn.tangsihai.hrm.dto.SMSCodeDto;
import cn.tangsihai.hrm.service.IVerifyCodeService;
import cn.tangsihai.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 获取图片验证码
     * @param key
     * @return
     */
    @GetMapping("/imageCode/{key}")
    public AjaxResult getImageCode(@PathVariable("key") String key){
        String imageCode = verifyCodeService.getImageCode(key);
        return AjaxResult.me().setResultObj(imageCode);
    }

    /**
     * 发送短信验证码
     * @param key
     * @return
     */
    @PostMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody SMSCodeDto dto){
        verifyCodeService.sendSmsCode(dto);
        return AjaxResult.me().setResultObj("短信发送成功");
    }
}
